<?php
/*
商品
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$basic=$this->setting;
$return['setting']=$basic;
$return['basic']=$basic;
$return['banner']=$basic['hdps'];
$return['pluginset']['footernav']=$this->setting['footernav4'];
$credit_types=credit_types(true);
if($_RQ['op']=='main'){
	$params=array('credit_type'=>4,'uniacid'=>$_SESSION['uniacid'],'status'=>1,'merchid'=>$_SESSION['onemerchid']);
	if($_RQ['cateid']){
		$params['cate']=$_RQ['cateid'];
		$return['params']['cateid']=intval($_RQ['cateid']);
		$return['cate']=pdo_get('jy_creditshop_category',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['cateid']));
	}
	if($_RQ['keyword']){
		if(is_numeric($_RQ['keyword'])){
			$params['id']=intval($_RQ['keyword']);
			$return['params']['id']=intval($_RQ['keyword']);
		}else{
			$params['title like']='%'.$_RQ['keyword'].'%';
			$return['params']['title']=$_RQ['keyword'];
		}
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 38;
	$total='';
	$list=pdo_getslice('jy_creditshop_goods',$params,array($pindex,$psize),$total,$fields,'','displayorder asc');
	if($list){
		foreach($list as &$item){
			if($item['is_moretype']){
				$item['creditmore']=$item['creditmore']?json_decode($item['creditmore'],true):array();
				$item['credit']=$item['creditmore'][0]['credit'];
				$item['credit_title']=$credit_types[$item['creditmore'][0]['credit_type']];
			}else{
				$item['credit_title']=$credit_types[$item['credit_type']];
			}
		}
	}
	$return['list']=$list;
	$return['category']=pdo_getall('jy_creditshop_category',array('uniacid'=>$_SESSION['uniacid'],'enabled'=>1,'isrecommand'=>1),array('name','id','thumb'),'','displayorder asc');
	set_html('title',$basic['title']?'商品-'.$basic['title']:'商品');
	$return['sharedata']=array(
		'title'=>$basic['share_title'],
		'desc'=>$basic['share_desc'],
		'link'=>custom_url('jy_credit4shop/goods4/',true),
		'imgUrl'=>ATTACHMENT_URL.$basic['share_image'],
	);
	exi($return);
}
//获取商品
if($_RQ['op']=='getlist'){
	//兑换商品
	$params=array('credit_type'=>4,'uniacid'=>$_SESSION['uniacid'],'status'=>1,'merchid'=>$_SESSION['onemerchid']);
	if($_RQ['cateid']){
		$params['cate']=$_RQ['cateid'];
	}
	if($_RQ['keyword']){
		if(is_numeric($_RQ['keyword'])){
			$params['id']=intval($_RQ['keyword']);
			$return['params']['id']=intval($_RQ['keyword']);
		}else{
			$params['title like']='%'.$_RQ['keyword'].'%';
			$return['params']['title']=$_RQ['keyword'];
		}
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	$total='';
	$list=pdo_getslice('jy_creditshop_goods',$params,array($pindex,$psize),$total,$fields,'','displayorder asc');
	if($list){
		foreach($list as &$item){
			if($item['is_moretype']){
				$item['creditmore']=$item['creditmore']?json_decode($item['creditmore'],true):array();
				$item['credit']=$item['creditmore'][0]['credit'];
				$item['credit_title']=$credit_types[$item['creditmore'][0]['credit_type']];
			}else{
				$item['credit_title']=$credit_types[$item['credit_type']];
			}
			$item['salenum']=price($item['salenum'],'',true);
		}
	}
	$return['list']=$list;
	exi($return);
}
